package controllers.useplan;

import hprose.HproseClinetService;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import play.cache.Cache;
import utils.convert.Convert;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import component.UserBis;

import constants.APIConstants;
import controllers.common.filter.BaseFilter;
import controllers.home.HomeAction;

public class UsePlanAction extends BaseFilter {
	
	public static void index() {
		JSONObject uses = new JSONObject();
		int totalCutter = 0;
		Map<String, Object> planParams = new HashMap<String, Object>();
		if ("2".equals(UserBis.currType())) {
			planParams.put("customer_id", UserBis.currUser());
			if(StringUtils.isNotBlank(params.get("date",String.class))){
				planParams.put("date", params.get("date",String.class));
			}
			Object[] arguments = new Object[]{planParams};
			String res = HproseClinetService.synCall(APIConstants.UPMSI_GETUSEPLANLIST, arguments,APIConstants.CUSTOMER_HOST, APIConstants.CUSTOMER_PORT);
			uses = JSONObject.parseObject(res);
			JSONArray jsonArr = JSONArray.parseArray(uses.get("data")+"");
			for (int i = 0; i < jsonArr.size(); i++) {
				JSONObject json = jsonArr.getJSONObject(i);
				totalCutter += Convert.convertToInt(json.get("num")+"",0);
			}
		} else {
			HomeAction.home();
		}
		totalCutter = (int) (totalCutter*1.15);
		render(uses,totalCutter);
	}
	public static void arrangePlan(){
		Map<String, Object> useplanParams = new HashMap<String, Object>();
		String[] arr = params.get("useplan").split(",");
		if ("2".equals(UserBis.currType())) {
			for (String str1 : arr) {
				String[] str2 = str1.split("=");
				useplanParams.put("operator_id", str2[0]);
				useplanParams.put("material_id", str2[1]);
				useplanParams.put("num", str2[2]);
				Object[] arguments = new Object[]{useplanParams};
				String res = HproseClinetService.synCall(APIConstants.UPMSI_ARRANGEPLAN, arguments,APIConstants.CUSTOMER_HOST, APIConstants.CUSTOMER_PORT);
			}
		}
		
	}
}
